package com.salton123.view.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.salton123.groupbargain.R
import com.salton123.groupbargain.ui.fm.PublishMissionStepOneActivity
import com.salton123.util.EventUtil
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**
 * User: newSalton@outlook.com
 * Date: 2019/9/22 16:22
 * ModifyTime: 16:22
 * Description:
 */
class CoinShopEntranceView : FrameLayout {
    private lateinit var mCoinCountTv: TextView
    private lateinit var ivPlus: ImageView

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        initView()
    }

    private fun initView() {
        LayoutInflater.from(context).inflate(R.layout.view_stub_coin_shop_entrance, this)
        mCoinCountTv = findViewById(R.id.color_canvas_coins_tv)
        ivPlus = findViewById(R.id.color_canvas_add_coin_iv)
        setOnClickListener { view ->
            PublishMissionStepOneActivity.start(context)
        }

    }

    fun show() {
        visibility = View.VISIBLE
    }

    fun hide() {
        visibility = View.GONE
    }

    fun setCount(count: Int) {
        mCoinCountTv!!.text = "" + count
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
//        EventUtil.register(this)
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
//        EventUtil.unregister(this)
    }

    fun hidePlus() {
        ivPlus.visibility = View.GONE
        setOnClickListener { }
    }
}
